<?php

/**
 * IndexController - The default controller class
 *
 * @author
 * @version
 */
require_once 'Zend/Controller/Action.php';
class AuthController extends App_Zend_Controller_Action_Shop
{
    public function init()
    {
    	$this->view->styleName = 'login';
    	parent::init();
    }

    public function errorAction()
    {
        $this->_helper->viewRenderer->setNoRender();
        $this->view->showMsg("You have been logged in!");
    }

    public function confirmcodeAction()
    {
        $this->getHelper ('layout')->disableLayout ();
        $this->_helper->viewRenderer->setNoRender();
        $this->view->confirmCode('buyerConfirmCode');
    }
    
    public function userstatuAction()
    {
    	$this->getHelper('layout')->disableLayout();
    	$this->getHelper('viewRenderer')->setNoRender();
    	$member=new CMember();
        if(!$member->isUser($this->getRequest()->getModuleName(),$this->getRequest()->getControllerName())||$_COOKIE[COOKIE_PRE.'member_type']!='buyer') {
            echo '0'; //Please Login First!            
        } else {
        	echo '1';
        }
    }

    public function registerAction()
    {
    	$this->view->styleName = 'register';
        $this->view->assign('current_action','register');
        $member=new CMember();
        if($member->isUser($this->_request->getModuleName(),$this->_request->getControllerName())) {
            $this->_redirect('/');
            return;
        }       
        $preurl=$this->_request->getParam("preurl");
        $this->view->assign('preurl',$preurl);
        
        $fenlei = new CFenlei('product');
		$clubList = $fenlei->getFenleiByPid(92);
		$this->view->clubList = $clubList;
        
        $this->view->webSiteTitle = 'Register for a fancycheapjersey.com Account';
        $this->view->webSiteKeywords = 'Register for a fancycheapjersey.com Account';
        //$this->view->webSiteDescription = 'Register for a fancycheapjersey.com Account';
        
        //SET META FOR FACEBOOK
        $this->getHelper ('layout')->getView()->headMeta()->setName('og:title', 'Register for a fancycheapjersey.com Account');
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:type', 'jersery');
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:url', MY_URL);
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:image', MY_URL.'/images/logo.jpg');
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:site_name', 'fancycheapjersey.com');
		$this->getHelper ('layout')->getView()->headMeta()->setName('fb:app_id', FACEBOOK_CONSUMER_ID);
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:description', 'Register for a fancycheapjersey.com Account');
    }

    public function loginAction()
    {
        $this->view->assign('current_action','login');
        $preurl = $this->_request->getParam("preurl");
        $error = $this->_request->getParam("error");
        $this->view->error = $error;
		if(!$preurl || $preurl == ''){
			$preurl = $_SERVER['HTTP_REFERER'];
		}
        $this->view->assign('preurl',$preurl);
        $this->view->webSiteTitle = 'Log In for a fancycheapjersey.com Account';
        $this->view->webSiteKeywords = 'Log In for a fancycheapjersey.com Account';
        //$this->view->webSiteDescription = 'Log In for a fancycheapjersey.com Account';

        //SET META FOR FACEBOOK
        $this->getHelper ('layout')->getView()->headMeta()->setName('og:title', 'Log In for a fancycheapjersey.com Account');
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:type', 'jersery');
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:url', MY_URL);
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:image', MY_URL.'/images/logo.jpg');
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:site_name', 'fancycheapjersey.com');
		$this->getHelper ('layout')->getView()->headMeta()->setName('fb:app_id', FACEBOOK_CONSUMER_ID);
		$this->getHelper ('layout')->getView()->headMeta()->setName('og:description', 'Log In for a fancycheapjersey.com Account');
    }

    public function forgetpassAction()
    {
        $this->view->assign('current_action','forgetpass');       
        $preurl=$this->_request->getParam("preurl");
        $this->view->assign('preurl',$preurl);
        $this->view->webSiteTitle = 'Forget password';
        $this->view->webSiteKeywords = 'Forget password';
        $this->view->webSiteDescription = 'Forget password'; 
    }

    public function doforgetpassAction()
    {
        $this->_helper->viewRenderer->setNoRender();
        $preurl=$this->_request->getParam("preurl");
        $username=$this->_request->getParam("username");
        $member = new CMember();
        $userArray = $member->getUserDetails(array('username'=>$username));
        if (empty($userArray)) {
        	$this->view->showMsg('Error','/');
        	return;
        }
    	$fp = fsockopen("www.fancycheapjersey.com", 80, $errno, $errstr, 30);
		if (!$fp) {   
			echo "$errstr ($errno)<br />\n";
		} else { 
			$out = "GET /auth-mail?mail=" . $username . "&type=getpass  HTTP/1.1\r\n";
			$out .= "Host: www.fancycheapjersey.com\r\n";
			$out .= "Connection: Close\r\n\r\n";
			fwrite($fp, $out);   
			fclose($fp);
		}
        $this->view->showMsg('Please check your E-mail and reset your password',$preurl);
    }
    
    public function getpassAction()
    {
    	$hash = $this->getRequest()->getParam('hash', '');
    	$getpass = new CGetpass();
    	$row = $getpass->fetchRow(array('hash = ?'=>$hash, 'isValid'=>1));
    	if ($row) {
    		$member = new CMember();
    		$userRow = $member->fetchRow(array('uid = ?'=>$row->uid));
    		$this->view->row = $userRow;
    		$this->view->hash = $hash;
    	} else {
    		$this->getHelper('viewRenderer')->setNoRender();
    		$this->view->showMsg('Error','/');
        	return;
    	}
    }
    
    public function dogetpassAction()
    {
    	$this->getHelper('viewRenderer')->setNoRender();
    	if ($this->getRequest()->isPost()) {
    		$hash = $this->getRequest()->getParam('hash', '');
    		$password = $this->getRequest()->getParam('password', '');
    		if (empty($password)) {
    			$this->view->showMsg('Error','/');    			
    		}
    		$getpass = new CGetpass();
    		$row = $getpass->fetchRow(array('hash = ?'=>$hash, 'isValid'=>1));
    		
	    	if ($row) {
	    		$getpass->setInvalid($hash);
	    		$member = new CMember();
       			$userArray = $member->getUserDetails(array('uid'=>$row->uid));
	    		$password = $this->getHelper('user')->encodePassword($password,$userArray[0]['username'],$userArray[0]['reg_time'],$userArray[0]['reg_ip']);
	    		$getpass->resetPass($row->uid, $password);
	    		$this->view->showMsg('Reset Success','/auth-login');
	    		return;
	    		
	    	} else {
	    		$this->getHelper('viewRenderer')->setNoRender();
	    		$this->view->showMsg('Erroaaar','/');
	        	return;
	    	}
    	}
    }

    public function checkAction()
    {
    	$this->getHelper('viewRenderer')->setNoRender();
    	$this->getHelper('layout')->disableLayout();
    	$member = new CMember();
    	if ($this->getRequest('isPost')) {
	        $username= $this->getRequest()->getParam('email');
	        $userArray=$member->getUserDetails(array('lower(username)'=>strtolower($username)));
	        if(count($userArray)>0) {
	            echo 0;
	        } else {
	        	echo 1;
	        }
    	}	
    }
    
    public function doregisterAction()
    {
        $this->_helper->viewRenderer->setNoRender();
        if(!$this->getRequest()->isPost()) {
            $this->_redirect('/');
            return false;
        }
        Zend_Session::start();
        $paramArray=$this->_request->getParams();

        $filters = array(
                '*'   => 'StringTrim'
        );

        $validators = array(
        );

        $input = new Zend_Filter_Input($filters, $validators, $paramArray);
        $member=new CMember();
        $username=$input->email;
        $userArray=$member->getUserDetails(array('lower(username)'=>strtolower($username)));
        if(count($userArray)>0) {
            $this->view->showMsg('The email you entered has been registered by others!');
            return false;
        }
    	preg_match("/^[A-Za-z0-9_@\-\s]+$/",$input->nick_name,$matches);
    	if(empty($matches)) {
    		$this->view->showMsg('Your nick name does not meet the rules!');
			return false;
    	}
        $preurl=$input->preurl;
        $userpass=$input->userpass;
        $time=time();
        $ip=$this->getHelper('User')->getIp();
        $md5Password=$this->getHelper('user')->encodePassword($userpass,$username,$time,$ip);
        
        //注册送积分活动状态
		$score = new CScore();
		$userScore = $score->registerScore();
		$statu = $score->registerScore('statu');
		
        $commonData=array(
                'username'=>$username,
                'userpass'=>$md5Password,
        		'passwd'=>$userpass,
                'email'=>$input->email,
        		'clubid'=>$input->clubid,
        		'subscribe'=>1,
                'reg_time'=>$time,
                'reg_ip'=>$ip,
                'member_type'=>'buyer',
                'email_code'=>'1',
                'is_enterprice'=>'0',        		
        );
        
        //优惠码注册
        $couponScore = 0; //赠送的积分
		$coupon = new CCouponCode();
		if (!empty($input->couponcode)) {
			if ($row = $coupon->isexist($input->couponcode)) { //存在该优惠码
				if (!$coupon->isexpires($input->couponcode)) { //优惠码未过期
					$couponScore = $score->dollar2score(COUPON_DOLLAR);
					if ($row->itemids) { //存在促销的商品					
						$score->addCart($row->itemids); //添加购物车					
					}
					$commonData['reg_from'] = $row->from;
				} else {
					$this->view->showMsg('The coupon code you input has expired!');
	            	return false;
				}
			} else {
				$this->view->showMsg('The coupon code you input is wrong!');
	            return false;
			}
		}
		      
        //活动开启，赠送积分
        if ($statu == 1) {
        	$commonData['integral'] = $userScore;
        }
        //优惠码的积分
        $commonData['integral'] = $commonData['integral'] + $couponScore;
        
        $buyerData=array(
                'nick_name'=>$input->nick_name,
                'btypeid'=>0
        );
        $buyer=new CBuyer();
        $uid=$buyer->create($commonData,$buyerData);
		
        // 传销绑定      
        
        $mlm = new CMlm();
        $inviteCode = CMlm::getInviteCode();
        if (empty($inviteCode)) {
        	$inviteCode = $this->getRequest()->getParam('invite_code', 0);
        }
        $inviteCode = intval($inviteCode);
        if ($inviteCode) {
       		$intitorId = $mlm->getMemberByInviteCode($inviteCode);
       		if ($intitorId) {
        		$mlm->bindMemberToInvitor($uid, $intitorId);
       		}
        }        
        
        
        if (is_numeric($uid)) {
        	//送5个坑
        	$CFlashcommon = new CFlashcommon();
        	$CFlashcommon->addItem($uid,5);
            Zend_Session::start();
            $this->setCookie($uid,$username,$md5Password,'0','buyer', $input->nick_name);
            $mail=new CMail();
            $mail->sendRegisterMailSync($input->email);
            if ($statu == 1) {
            	$fenlei = new CFenlei('product');
				$fenlei->refreshIntegral();
				$dollar = $score->score2dollar($commonData['integral']);
				if ($couponScore > 0) {
					$this->view->showMsg('Welcome to join us! you have got ' . $dollar . ' dollar! ', '/product-showitem');
				} else {
            		$this->view->showMsg('Welcome to join us! you have got ' . $dollar . ' dollar! ', $input->preurl);
				}
            } else {
            	$this->view->showMsg('Welcome to join us!', $input->preurl);
            }
            return true;
        } else {
            $this->view->showMsg($uid);
            return false;
        }
    }
    
	public function doquickregisterAction()
    {
        $this->_helper->viewRenderer->setNoRender();
        if(!$this->getRequest()->isPost()) {
            $this->_redirect('/');
            return false;
        }
        Zend_Session::start();
        $paramArray=$this->_request->getParams();

        $filters = array(
                '*'   => 'StringTrim'
        );

        $validators = array(
        );

        $input = new Zend_Filter_Input($filters, $validators, $paramArray);
        $member=new CMember();
        $username=$input->username;
        $userArray=$member->getUserDetails(array('lower(username)'=>strtolower($username)));
        if(count($userArray)>0) {
            $this->view->showMsg('The email you entered has been registered by others!', '/product-tip');
            return false;
        }
    	
        $preurl=$input->preurl;
        $userpass=$input->userpass;
        $time=time();
        $ip=$this->getHelper('User')->getIp();
        $md5Password=$this->getHelper('user')->encodePassword($userpass,$username,$time,$ip);
        
        //注册送积分活动状态
		$score = new CScore();
		$userScore = $score->registerScore();
		$statu = $score->registerScore('statu');
		
        $commonData=array(
                'username'=>$username,
                'userpass'=>$md5Password,
        		'passwd'=>$userpass,
                'email'=>$username,
        		'clubid'=>0,
        		'subscribe'=>1,
                'reg_time'=>$time,
                'reg_ip'=>$ip,
                'member_type'=>'buyer',
                'email_code'=>'1',
                'is_enterprice'=>'0',        		
        );
        
        //优惠码注册
        $couponScore = 0; //赠送的积分
		$coupon = new CCouponCode();
		if (!empty($input->couponcode)) {
			if ($row = $coupon->isexist($input->couponcode)) { //存在该优惠码
				if (!$coupon->isexpires($input->couponcode)) { //优惠码未过期
					$couponScore = $score->dollar2score(COUPON_DOLLAR);
					if ($row->itemids) { //存在促销的商品					
						$score->addCart($row->itemids); //添加购物车					
					}
					$commonData['reg_from'] = $row->from;
				} else {
					$this->view->showMsg('The coupon code you input has expired!');
	            	return false;
				}
			} else {
				$this->view->showMsg('The coupon code you input is wrong!');
	            return false;
			}
		}
		      
        //活动开启，赠送积分
        if ($statu == 1) {
        	$commonData['integral'] = $userScore;
        }
        //优惠码的积分
        $commonData['integral'] = $commonData['integral'] + $couponScore;
        
        $buyerData=array(
                'nick_name'=>$username,
                'btypeid'=>1
        );
        $buyer=new CBuyer();
        $uid=$buyer->create($commonData,$buyerData);
        
        // 传销绑定      
        
        $mlm = new CMlm();
        $inviteCode = CMlm::getInviteCode();
        if (empty($inviteCode)) {
        	$inviteCode = $this->getRequest()->getParam('invite_code', 0);
        }
        $inviteCode = intval($inviteCode);
        if ($inviteCode) {
       		$intitorId = $mlm->getMemberByInviteCode($inviteCode);
       		if ($intitorId) {
        		$mlm->bindMemberToInvitor($uid, $intitorId);
       		}
        }       
        

        if (is_numeric($uid)) {
            Zend_Session::start();
            $this->setCookie($uid,$username,$md5Password,'0','buyer', $username);
            $mail=new CMail();
            $mail->sendRegisterMailSync($input->email);
            if ($statu == 1) {
            	$fenlei = new CFenlei('product');
				$fenlei->refreshIntegral();
				$dollar = $score->score2dollar($commonData['integral']);
				if ($couponScore > 0) {
					$this->view->showMsg('Welcome to join us! you have got ' . $dollar . ' dollar! ', $preurl);
				} else {
            		$this->view->showMsg('Welcome to join us! you have got ' . $dollar . ' dollar! ', $preurl);
				}
            } else {
            	$this->view->showMsg('Welcome to join us!', $preurl);
            }
            return true;
        } else {
            $this->view->showMsg($uid);
            return false;
        }
    }

    public function dologinAction()
    {

        $this->_helper->viewRenderer->setNoRender();

        if(!$this->getRequest()->isPost())
        {

            $this->view->showMsg("发生未知错误!");

            return false;

        }

        $paramArray=$this->_request->getParams();

        $filters = array(
                '*'   => 'StringTrim'
        );

        $validators = array(
        );

        $input = new Zend_Filter_Input($filters, $validators, $paramArray);

        Zend_Session::start();

        $username=$input->username;

        $userpass=$input->userpass;

        $useryz=$input->useryz;

        //if($username==''||$userpass==''||$useryz=='')
        if($username==''||$userpass=='')
        {

            $this->view->showMsg("Please full fill your login form!");

            return false;

        }
        /*
		if(strtolower($useryz)!=strtolower($_SESSION['buyerConfirmCode'])){
			
			$this->view->showMsg("Wrong verified code!");
			
			return false;
			
		}
        */
        $preurl=$this->_request->getParam("preurl");

        $preurl=$preurl==''?MY_URL:$preurl;

        $member=new CMember();

        $thisArray=$member->login($username,$userpass,'buyer');
        if(count($thisArray)==0)
        {
        	$this->_redirect('/auth-login?error=loginError&preurl=' . $preurl);
        	return;
            $this->view->showMsg("Please check up your username or password!","auth-login?preurl=".$preurl);
            return false;

        }
        $this->setCookie($thisArray['uid'],$thisArray['username'],$thisArray['userpass'],$thisArray['is_enterprice'],$thisArray['member_type'], $thisArray['nick_name']);
		
        if (defined('SELL_VALIDATE')) { //有新的邀请人，更新
        	$invId = isset($_COOKIE[COOKIE_PRE.'inv_facebook_id']) ? $_COOKIE[COOKIE_PRE.'inv_facebook_id'] : 0;
			$myId = isset($_COOKIE[COOKIE_PRE.'my_facebook_id']) ? $_COOKIE[COOKIE_PRE.'my_facebook_id'] : 0;
			
        	$row = array('my_facebook_id'=>$myId, 'inv_facebook_id'=>$invId, 'add_time'=>time());        	
			$invModel = new CPyramidMemberInv();
			$invModel->add($row, $thisArray['uid']);
        } else {
        	$invModel = new CPyramidMemberInv();
        	$row = $invModel->getInv($thisArray['uid']);
        	if ($row) {
	        	setcookie(COOKIE_PRE.'inv_facebook_id', $row->inv_facebook_id, time()+3600*24*365, '/');
				setcookie(COOKIE_PRE.'my_facebook_id', $row->my_facebook_id, time()+3600*24*365, '/');
        	}
        }
        //$this->view->showMsg("Login succeed!",$preurl);
		$this->_redirect($preurl) ;

        return true;

    }

    public function getinfoAction()
    {

        $this->getHelper ('layout')->disableLayout ();

        $member=new CMember();

        $isUser=$member->isUser();

        if($isUser)
        {

            $this->view->assign('uid',$_COOKIE[COOKIE_PRE.'uid']);

            $this->view->assign('username',$_COOKIE[COOKIE_PRE.'username']);

        }

        $this->view->assign('isUser',$isUser);

    }

    public function logoutAction()
    {

        $this->view->assign('current_action','logout');

        $this->_helper->viewRenderer->setNoRender();

        Zend_Session::start();

        session_unset();

        session_destroy();

        setcookie(COOKIE_PRE.'uid','',-10,'/');

        setcookie(COOKIE_PRE.'username','',-10,'/');

        setcookie(COOKIE_PRE.'userpass','',-10,'/');
        setcookie(COOKIE_PRE.'nickname','',-10,'/');

        setcookie(COOKIE_PRE.'is_enterprice','',-10,'/');

        setcookie(COOKIE_PRE.'member_type','',-10,'/');

        setcookie(COOKIE_PRE.'member_admin','',-10,'/');

        //$this->view->showMsg("Logout succeed!",$_SERVER['HTTP_REFERER']);
		//$preurl=$_SERVER['HTTP_REFERER']==''?MY_URL:$_SERVER['HTTP_REFERER'];
		$this->_redirect(MY_URL) ;

    }

    public function setCookie($uid,$username,$userpass,$is_enterprice,$member_type, $nick_name = '')
    {
    	//合并购物车
    	$cart = new CCart();
    	$sessionHash = $_COOKIE[COOKIE_PRE.'product_buy_session'];
    	
    	if ($sessionHash) { //存在未登录的购物车
    		$cartStr = $cart->getCartStr($sessionHash);
			if ($cartStr) { //存在
           		$shoppingArray=json_decode(stripslashes($cartStr),true);
           		$row = $cart->fetchRow(array('uid = ?'=>$uid, 'expires > ?'=>time()));
           		if ($row) { //存在旧的购物车,不存在会自动转换
           			$cartStr2 = $cart->getCartStrByUid($uid);
           			$shoppingArray2 = json_decode(stripslashes($cartStr2), true);
           			$newShoppingArray=array();
		            foreach ((array)$shoppingArray2 as $key => $value)
		            {
		                $newShoppingArray[$key]['pattern_name']=$value['pattern_name'];
						$newShoppingArray[$key]['counts']=$value['counts'];
	                    $newShoppingArray[$key]['pattern_size']=$value['pattern_size'];
	                    $newShoppingArray[$key]['printMesg']=$value['printMesg'];
	                    $newShoppingArray[$key]['printAmounts']=$value['printAmounts'];
	                    $newShoppingArray[$key]['badge_patch_amount']=$value['badge_patch_amount'];
	                    $newShoppingArray[$key]['badge_patch_money']=$value['badge_patch_money'];
	                    $newShoppingArray[$key]['BadgePatch']=$value['BadgePatch'];
	                    $newShoppingArray[$key]['originalname_num']=$value['originalname_num'];
	                    $newShoppingArray[$key]['originalprintAmounts']=$value['originalprintAmounts'];
	                    $newShoppingArray[$key]['name_num']=$value['name_num'];
	                    $newShoppingArray[$key]['printAmounts']=$value['printAmounts'];	                    
		            }
		            
           			foreach ((array)$shoppingArray as $key => $value)
		            {
		                $newShoppingArray[$key]['pattern_name']=$value['pattern_name'];
						$newShoppingArray[$key]['counts']=$value['counts'];
	                    $newShoppingArray[$key]['pattern_size']=$value['pattern_size'];
	                    $newShoppingArray[$key]['printMesg']=$value['printMesg'];
	                    $newShoppingArray[$key]['printAmounts']=$value['printAmounts'];
	                    $newShoppingArray[$key]['badge_patch_amount']=$value['badge_patch_amount'];
	                    $newShoppingArray[$key]['badge_patch_money']=$value['badge_patch_money'];
	                    $newShoppingArray[$key]['BadgePatch']=$value['BadgePatch'];
	                    $newShoppingArray[$key]['originalname_num']=$value['originalname_num'];
	                    $newShoppingArray[$key]['originalprintAmounts']=$value['originalprintAmounts'];
	                    $newShoppingArray[$key]['name_num']=$value['name_num'];
	                    $newShoppingArray[$key]['printAmounts']=$value['printAmounts'];	                    
		            }
		            
		            $cartStr=json_encode($newShoppingArray);
		            $row = array('cart_session_id'=>$sessionHash, 'cart_str'=>addslashes($cartStr), 'expires'=>time()+3600*24*180, 'uid'=>$uid);
	        		$cart->setCartStrByUid($uid, $row);
           		}	
			}
    	}
    	
        setcookie(COOKIE_PRE.'uid',$uid,null,'/');
        setcookie(COOKIE_PRE.'username',$username,null,'/');
        setcookie(COOKIE_PRE.'userpass',$userpass,null,'/');
        setcookie(COOKIE_PRE.'nickname',$nick_name,null,'/');
        setcookie(COOKIE_PRE.'is_enterprice',$is_enterprice,null,'/');
        setcookie(COOKIE_PRE.'member_type',$member_type,null,'/');
        setcookie(COOKIE_PRE.'member_admin','adminb',null,'/');

        $sellerSession=new Zend_Session_Namespace('member');

        $sellerSession->userCode=$userpass;
        $sellerSession->userpass=$userpass;
        $sellerSession->uid=$uid;
        $sellerSession->member_type=$member_type;


    }
    
    public function clubAction()
    {
    	$member=new CMember();
        if($member->isUser($this->_request->getModuleName(),$this->_request->getControllerName())) {
			$user = $member->getUserDetails(array('uid'=>$_COOKIE[COOKIE_PRE . 'uid']));
			if (empty($user[0]['clubid'])) {
				if ($this->getRequest()->isPost()) {
					$clubid = intval($this->getRequest()->getParam('clubid'));
					if ($clubid > 0 && $member->updateUserDetail(array('clubid'=>$clubid), array('uid'=>$_COOKIE[COOKIE_PRE . 'uid']))) {
						$this->getHelper('viewRenderer')->setNoRender();
						$fenlei = new CFenlei('product');
						$fenlei->refreshIntegral();
						$this->view->showMsg("Success!", '/');
						return;
					} else {
						$this->getHelper('viewRenderer')->setNoRender();
						$this->view->showMsg("Error!", '/auth-club');
						return;
					}
				}
				$fenlei = new CFenlei('product');
				$clubList = $fenlei->getFenleiByPid(92);
				$this->view->clubList = $clubList;
			} else {
				$this->getHelper('viewRenderer')->setNoRender();
				$this->view->showMsg("You have choos club!", '/');
			}
        } else {
        	$this->getHelper('viewRenderer')->setNoRender();
        	$this->view->showMsg("Please Login First", '/auth-login?preurl=/auth-club');
        }
    }
    
	public function mailAction()
    {
    	ignore_user_abort();
    	set_time_limit(0);
    	$this->getHelper('layout')->disableLayout();
    	$this->getHelper('viewRenderer')->setNoRender();
    	$type = $this->getRequest()->getParam('type', '');
    	$mail = $this->getRequest()->getParam('mail', '');
    	if (empty($mail) || empty($type)) {
    		return;
    	}
    	
    	if ($type == 'reg') {    		
    		$mailer=new CMail();
            $mailer->sendRegisterMail($mail);          
            echo 'reg';
    	}
    	if ($type == 'getpass') {
    		$member = new CMember();
    		$username = $mail;
	        $userArray = $member->getUserDetails(array('username'=>$username));
    		$getPass = new CGetpass();
		    $hash = $getPass->genHash($userArray[0]['username'], $userArray[0]['uid']);
		    $getPass->add(array('uid'=>$userArray[0]['uid'], 'hash'=>$hash, 'addtime'=>date('Y-m-d H:i:s', time())));
		    $to = $username;
		    $subject = "Reset Your Password";
		    $message = "Please Reset Your Password By Click <a href=\"" . MY_URL . "/auth-getpass?hash=" . $hash . "\">Reset Password</a>";
		    $from = "service@fancycheapjersey.com";
//		    $headers = "MIME-Version: 1.0" . "\r\n";
//		    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
//		    $headers .= "From: $from";
//		    mail($to,$subject,$message,$headers);
			$mailer=new CMail();
            $mailer->sendEmail($from, $to, $subject, $message); 
		    echo 'getpass';
    	}
    }

    public function postAction()
    {



        //$this->_helper->viewRenderer->setNoRender();

        //$this->getHelper ('layout')->disableLayout ();

    }


}
